from PIL import Image
import numpy as np

source_image_dir = './image'
taget_image_dir = './image_output'
source_image = '1.jpg'

NormalizationScale = (256, 256)  # 归一化尺寸
DiscretizationSize = 16 # 颜色减少，离散化处理

im_1 = np.array(
    Image.open("%s/%s"%(source_image_dir,source_image)).resize((256,256))
)
im_2 = im_1//DiscretizationSize*DiscretizationSize
Image.fromarray(im_2).save(
    '1.jpg'
)


# k-means
from sklearn.cluster import KMeans
# 构造数据样本点集X，并计算 K-means 聚类
X = []
for row in im_2:
    for ele in row:
        X.append(ele)
# print(X)
kmeans = KMeans(n_clusters = 5, random_state=0).fit(X)

# 输出及聚类后的每个样本点的标签（类别），预测新的样本点所属类别
print(kmeans.labels_)
for label in kmeans.labels_:
    print(label)
print(kmeans)
# print(kmeans.predict([0,0,0],[4,4,0],[2,1,0]))
